<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>hello</title>
    <!-- 导入vue包 -->
    <script src="./lib/vue2.6.10.js"></script>
    <!-- 导入路由的包 -->
    <script src="./lib/vue-router.js"></script>
    <style>
        .act{
            border: 1px solid gray;
            background-color: rosybrown;
            font-size: 16px;
        }
        .v-enter,.v-leave-to{
            opacity: 0;
            transform: translateX(120px);
        }
        .v-enter-active,.v-leave-active {
            transition: all 0.5s ease;
        }
    </style>
</head>
<body>
    <div id="app">
        <router-link to="/login">登录</router-link> | <router-link to="/reg">注册</router-link>
        <hr>
        <transition mode="out-in">
            <router-view></router-view>
        </transition>
    </div>


    <script>

        var login = {
            template : "<h1>登录组件</h1>"
        }
        var reg = {
            template : "<h1>注册组件</h1>"
        }
        // 创建一个路由对象，当导入vue-route后，window全局对象中就挂载了一个VueRouter实例
        var routerObj = new VueRouter({
            // routes // 路由匹配规则“们”
            routes: [
                // path: 路由匹配规则 ，component: 组件的模板对象
                {path: "/", redirect: '/login'}, // 路由重定向
                {path: "/login", component: login},
                {path: "/reg", component: reg}
            ],
            linkActiveClass: "act"
        });

        // 创建一个vue实例
        var vm = new Vue({
            el:'#app', // 当前new的这个vue实例要控制的DOM
            data: {     // 所有的数据

            },
            // 将路由注册对象注册到vm实例中
            router: routerObj,

        })

    </script>
</body>
</html>